package practice.exception

import utility.CustomLogger

import scala.util.{Failure, Success, Try}

/**
  * Created by lovepocky on 16/7/11.
  */
object exceptionHandle extends CustomLogger {
	def main(args: Array[String]) {
		loggers.console.info("exception handle start")
		classicHandle()
		scalaHandle(true)
		scalaHandle(false)
		loggers.console.info("exception handle end")
	}

	def classicHandle() = {
		try {
			throw new Exception("classic exception")
		} catch {
			case e: Exception =>
				loggers.console.error("classic exception message", e)
		}
	}

	def scalaHandle(isException: Boolean) = {
		Try {
			if (isException) {
				throw new Exception("scala test")
			} else {
				"hello"
			}
		} match {
			case Success(s) => loggers.console.info(s)
			case Failure(e) => loggers.console.error("message", e)
		}
	}
}
